package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;

import com.updateNew.MyIsif;
import come.tool.JDialog.TiShiUtil;
import org.come.Frame.NPCJfram;
import org.come.Frame.OptionsJframe;
import org.come.Frame.ZhuFrame;
import org.come.bean.AllMapBean;
import org.come.bean.AllNpcBean;
import org.come.bean.HeadImgBean;
import org.come.bean.NpcInfoBean;
import org.come.control.NpcMenuControl;
import org.come.entity.Goodstable;
import org.come.model.Door;
import org.come.model.Gamemap;
import org.come.model.Npctable;
import org.come.mouslisten.GoodsMouslisten;
import org.come.npc.TP;
import org.come.until.*;

import com.tool.btn.FormsOnOffBtn;
import com.tool.btn.RoleCaoZuoBtn;
import com.tool.image.ImageMixDeal;
import com.tool.tcpimg.UIUtils;



//npc查询功能集合
public class ChaojifeiListJpanel extends JPanel {
	private JLabel labtext1, labtext2, labtext3,// 当前排名
			labtext4;// 当前排行榜排名
	private static JLabel labtext5;
	private static JLabel labtext6;
	private int day = 0;
	private static NPCJpanel npcJpanel;
	// 滚动条
	private static JScrollPane jScrollPane1, jScrollPane2;
	// 选中的地图
	private static DefaultListModel<String> pankModel,pankModel1;
	// 类型
	private static JList<String> listPank,listPank1;

	private static JTextField findName,findName1;

	private static RoleCaoZuoBtn sureGive, deleteGive;// 确定查询，取消

	private static List<Map<String, Object>> dataNpcMapListSX;
	private static List<Map<String, Object>> dataNpcMapList;
	private static List<Map<String, Object>> dataNpcMapListgds;

	private static List<String> selectNpc;

	private Goodstable good;
	private static String[] Fvalue;
	private static JTextArea testMes;// 用来显示聊天信息
	private static List<String> npcfunction = new ArrayList<>();
	private static int ys = 0;
	private static String[] npcsStrings;// npc 功能集合
	private static JList<String> list1;
	private static ImageIcon headImg;
	private static int headHeight = 0;
	public String npczb;
	public static String npcfeiji;
	// 排行榜信息表格中的对象
	private static DefaultTableModel tableModel;
	public ChaojifeiListJpanel() {
		if (MyIsif.getStyle().equals("水墨UI")){

			this.setPreferredSize(new Dimension(540, 480));
			this.setLayout(null);
			this.setBackground(UIUtils.Color_BACK);

			findName = new JTextField();// 查询的物品名称输入
			findName.setBounds(115, 112, 210, 20);
			findName.setOpaque(false);
			findName.setBorder(BorderFactory.createEmptyBorder());
			findName.setForeground(Color.white);
			findName.setCaretColor(Color.white);
			findName.setFont(new Font("宋体",Font.PLAIN,15));
			this.add(findName);


			Font font = new Font("楷体", 0, 16);
			labtext5 = new JLabel();
			labtext5.setForeground(Color.white);
			labtext5.setFont(font);
			labtext5.setBounds(115,69, 320, 20);
			labtext5.setText("请输入并搜索NPC");
			this.add(labtext5);


			// 关闭按钮事件
			FormsOnOffBtn offBtn = new FormsOnOffBtn("inkImg/old/2/1.png", 1, 1101);
			offBtn.setBounds(540-37, 10, 25, 25);
			this.add(offBtn);
			font = new Font("楷体", Font.BOLD, 20);
			//


			labtext3 = new JLabel();
			labtext3.setForeground(Color.YELLOW);
			labtext3.setFont(font);
			labtext3.setBounds(288, -10, 250, 50);
			labtext3.setText("NPC查询");
//		this.add(labtext3);

			font = new Font("楷体", 0, 16);

			labtext4 = new JLabel();
			labtext4.setForeground(Color.YELLOW);
			labtext4.setFont(font);
			labtext4.setBounds(70, 45, 250, 50);
			labtext4.setText("NPC名称");
//		this.add(labtext4);
			if(dataNpcMapList!=null&& dataNpcMapList.size()>0) {
				getlisysta(dataNpcMapList);
			}else {
				getlisysta(null);
			}

			// 申请列表滚动条
			jScrollPane1 = new JScrollPane(listPank);
			jScrollPane1.setVerticalScrollBarPolicy(22);
			jScrollPane1.getVerticalScrollBar().setUI(new SrcollPanelUI());
			jScrollPane1.getViewport().setOpaque(false);
			jScrollPane1.setOpaque(false);
			jScrollPane1.setBounds(23, 176, 131, 276);
			jScrollPane1.setBorder(BorderFactory.createEmptyBorder());
			jScrollPane1.setHorizontalScrollBarPolicy(31);
			this.add(jScrollPane1);

			// 申请列表滚动条
			jScrollPane2 = new JScrollPane(listPank1);
			jScrollPane2.setVerticalScrollBarPolicy(22);
			jScrollPane2.getVerticalScrollBar().setUI(new SrcollPanelUI());
			jScrollPane2.getViewport().setOpaque(false);
			jScrollPane2.setOpaque(false);
			jScrollPane2.setBounds(163, 176, 352, 276);
			jScrollPane2.setBorder(BorderFactory.createEmptyBorder());
			jScrollPane2.setHorizontalScrollBarPolicy(31);
			this.add(jScrollPane2);

			sureGive = new RoleCaoZuoBtn("skin/8100226/newbutton/B21.png", 1, "搜 索", 1101, UIUtils.COLOR_BTNPUTONG);
			sureGive.setBounds(350, 109, 79, 24);
			this.add(sureGive);
			sureGive = new RoleCaoZuoBtn("inkImg/hongmu/1/6026.png", 1, "传送", 1102, UIUtils.COLOR_BTNPUTONG);
			sureGive.setBounds(555, 55, 68, 26);
//		this.add(sureGive);

		}else {
			this.setPreferredSize(new Dimension(540, 480));
			this.setLayout(null);
			this.setBackground(UIUtils.Color_BACK);

			findName = new JTextField();// 查询的物品名称输入
			findName.setBounds(112, 102, 210, 20);
			findName.setOpaque(false);
			findName.setBorder(BorderFactory.createEmptyBorder());
			findName.setForeground(Color.white);
			findName.setCaretColor(Color.white);
			findName.setFont(new Font("宋体",Font.PLAIN,15));
			this.add(findName);


			Font font = new Font("楷体", 0, 16);
			labtext5 = new JLabel();
			labtext5.setForeground(Color.white);
			labtext5.setFont(font);
			labtext5.setBounds(113,59, 320, 20);
			labtext5.setText("请输入并搜索NPC");
			this.add(labtext5);


			// 关闭按钮事件
			FormsOnOffBtn offBtn = new FormsOnOffBtn("img/xy2uiimg/8_jpg.button.btn_close.jpg", 1, 1101);
			offBtn.setBounds(540-43, 5, 25, 25);
			this.add(offBtn);
			font = new Font("楷体", Font.BOLD, 20);
			//


			labtext3 = new JLabel();
			labtext3.setForeground(Color.YELLOW);
			labtext3.setFont(font);
			labtext3.setBounds(288, -10, 250, 50);
			labtext3.setText("NPC查询");
//		this.add(labtext3);

			font = new Font("楷体", 0, 16);

			labtext4 = new JLabel();
			labtext4.setForeground(Color.YELLOW);
			labtext4.setFont(font);
			labtext4.setBounds(70, 45, 250, 50);
			labtext4.setText("NPC名称");
//		this.add(labtext4);
			if(dataNpcMapList!=null&& dataNpcMapList.size()>0) {
				getlisysta(dataNpcMapList);
			}else {
				getlisysta(null);
			}

			// 申请列表滚动条
			jScrollPane1 = new JScrollPane(listPank);
			jScrollPane1.setVerticalScrollBarPolicy(22);
			jScrollPane1.getVerticalScrollBar().setUI(new SrcollPanelUI());
			jScrollPane1.getViewport().setOpaque(false);
			jScrollPane1.setOpaque(false);
			jScrollPane1.setBounds(23, 176, 131, 276);
			jScrollPane1.setBorder(BorderFactory.createEmptyBorder());
			jScrollPane1.setHorizontalScrollBarPolicy(31);
			this.add(jScrollPane1);

			// 申请列表滚动条
			jScrollPane2 = new JScrollPane(listPank1);
			jScrollPane2.setVerticalScrollBarPolicy(22);
			jScrollPane2.getVerticalScrollBar().setUI(new SrcollPanelUI());
			jScrollPane2.getViewport().setOpaque(false);
			jScrollPane2.setOpaque(false);
			jScrollPane2.setBounds(163, 176, 352, 276);
			jScrollPane2.setBorder(BorderFactory.createEmptyBorder());
			jScrollPane2.setHorizontalScrollBarPolicy(31);
			this.add(jScrollPane2);

			sureGive = new RoleCaoZuoBtn("inkImg/hongmu/1_png.button.btn_xy.png", 1, "搜 索", 1101, UIUtils.COLOR_BTNPUTONG1);
			sureGive.setBounds(350, 107, 79, 24);
			this.add(sureGive);
			sureGive = new RoleCaoZuoBtn("inkImg/hongmu/1/6026.png", 1, "传送", 1102, UIUtils.COLOR_BTNPUTONG);
			sureGive.setBounds(555, 55, 68, 26);
//		this.add(sureGive);
		}
	}


	public void getNpcName(int indexs) {
		if(dataNpcMapListSX!=null && dataNpcMapListSX.size()>0) {
			Map<String, Object> maps = dataNpcMapListSX.get(indexs);
			List<Map<String, Object>> list = (List<Map<String, Object>>) maps.get("npcList");
			for(int i=0;i<list.size();i++) {
				listPank1 = new JList<String>();
				listPank1.setSelectionBackground(new Color(33, 42, 52));
				listPank1.setSelectionForeground(Color.yellow);
				listPank1.setForeground(Color.white);
				listPank1.setFont(new Font("楷体", 1, 16));
				listPank1.setBackground(new Color(0, 0, 0, 0)); // 设置列表框为透明背景
				listPank1.setFixedCellHeight(25);
				pankModel1.addElement(list.get(i).get("npcName").toString());
				listPank1.setModel(pankModel1);
			}
		}
	}


	public static List<Map<String, Object>> getlist(String name){
		String text = findName.getText();
		//总数据
		List<Map<String, Object>> dataNpcMapList = new ArrayList<Map<String, Object>>();

		//npc数据
		List<Npctable> npcList = new ArrayList<Npctable>();
		AllNpcBean allNpcBean = UserMessUntil.getAllNpcBean();
		if(allNpcBean!=null) {
			Map<String, NpcInfoBean> npc = allNpcBean.getAllNpcInfo();
			for (Entry<String, NpcInfoBean> entry : npc.entrySet()) {
				if(entry.getValue().getNpctable().getNpcname()!=null && !"".equals(entry.getValue().getNpctable().getNpcname())) {
					npcList.add(entry.getValue().getNpctable());
				}
			}
		}
		//map数据
		AllMapBean allMapBean = UserMessUntil.getAllmapbean();
		Map<String, Gamemap> mapa = allMapBean.getAllMap();
		List<Gamemap> mapListALL = new ArrayList<Gamemap>();
		List<Gamemap> mapList = new ArrayList<Gamemap>();
		for (Entry<String, Gamemap> entry : mapa.entrySet()) {
			if(entry.getValue().getMapnpc()!=null && !"".equals(entry.getValue().getMapnpc())) {
				mapListALL.add(entry.getValue());
			}
		}
		if(mapListALL!=null &&mapListALL.size()>0) {
			for(Gamemap gamemap:mapListALL) {
				if("1".equals(gamemap.getMapflag())) {
					mapList.add(gamemap);
				}
			}
		}
		if(mapList!=null && mapList.size()>0) {
			for(Gamemap gamemap:mapList) {
				List<Map<String, Object>> mapNpcList = new ArrayList<Map<String, Object>>();
				Map<String, Object> maps = new HashMap<>();
				int x = Integer.parseInt(gamemap.getWidth())/2;
				int y = Integer.parseInt(gamemap.getHeight())/2;
				String mapName = gamemap.getMapname();
				String mapxy = x+","+y;
				String mapid = gamemap.getMapid();
				String[] mapnpc = gamemap.getMapnpc().split("\\|");
				List<String> mapnpcList = new ArrayList<String>();
				if(mapnpc!=null && mapnpc.length>0) {
					for(String npcs:mapnpc) {
						int result1 = npcs.indexOf("-");
						if(result1 != -1){
							String[] mapnpcs = npcs.split("\\-");
							if(mapnpcs.length>1) {
								int i = Integer.parseInt(mapnpcs[1])-Integer.parseInt(mapnpcs[0])+1;
								for(int j =0; j<i; j++) {
									int s = Integer.parseInt(mapnpcs[0])+j;
									mapnpcList.add(s+"");
								}
							}
						}else {
							mapnpcList.add(npcs);
						}
					}
					//

					if(mapnpcList!=null && mapnpcList.size()>0) {
						for(String npc : mapnpcList) {
							for(Npctable npctable:npcList) {
								if(npc.equals(npctable.getNpcid())) {
									Map<String, Object> mapNpc = new HashMap<>();
									mapNpc.put("npcName", npctable.getNpcname());
									mapNpc.put("npcx", npctable.getTx());
									mapNpc.put("npcy", npctable.getTy());
									mapNpcList.add(mapNpc);
								}
							}
						}
					}
				}
				maps.put("mapName",  mapName);
				maps.put("mapxy",  mapxy);
				maps.put("mapid",  mapid);
				if(mapNpcList!=null && mapNpcList.size()>0) {
					maps.put("npcList",  mapNpcList);
					dataNpcMapList.add(maps);
				}
			}
		}
		//npc名字检索

		//检索后的总数据
		List<Map<String, Object>> dataNpcMapListJS = new ArrayList<Map<String, Object>>();

		if(dataNpcMapList!=null && dataNpcMapList.size()>0) {
			for(Map<String, Object> map : dataNpcMapList) {
				Map<String, Object> maps = new HashMap<>();
				List<Map<String, Object>> mapNpcList2 = new ArrayList<Map<String, Object>>();
				List<Map<String, Object>> mapNpcList = (List<Map<String, Object>>) map.get("npcList");
				if(mapNpcList!=null && mapNpcList.size()>0) {
					for(Map<String, Object> map2:mapNpcList) {
						int result1 = map2.get("npcName").toString().indexOf(text);
						if(result1 != -1){
							mapNpcList2.add(map2);
							maps = map;
							maps.put("npcList",  mapNpcList2);
							dataNpcMapListJS.add(maps);
						}
					}
				}
			}
		}
		//如果有检索数据去重
		if(text!=null && text.length()>0) {
			dataNpcMapListgds = dataNpcMapList = removeRepeatMapByKey(dataNpcMapListJS,"mapName");
		}
		//返回最终结果
		dataNpcMapListSX = dataNpcMapList;
		ChaojifeiListJpanel();
		return dataNpcMapList;
	}

	//
	public static void getlisysta(List<Map<String, Object>> dataNpcMapList) {
		if(dataNpcMapList!=null && dataNpcMapList.size()>0) {

		}else {
			dataNpcMapList = getlist(findName.getText());
		}
		pankModel = new DefaultListModel<String>();
		for(int i = 0; i<dataNpcMapList.size(); i++) {
			Font font = new Font("楷体", 0, 18);

			// 申请列表
			listPank = new JList<String>();
			listPank.setSelectionBackground(new Color(33, 42, 52));
			listPank.setSelectionForeground(Color.yellow);
			listPank.setForeground(Color.white);
			listPank.setFont(new Font("楷体", 1, 16));
			listPank.setBackground(new Color(0, 0, 0, 0)); // 设置列表框为透明背景
			listPank.setFixedCellHeight(25);
// 	        pankModel.addElement(dataNpcMapList.get(i).get("mapName").toString()+","+dataNpcMapList.get(i).get("mapid").toString());
			pankModel.addElement(dataNpcMapList.get(i).get("mapName").toString());
			listPank.setModel(pankModel);



			pankModel1 = new DefaultListModel<String>();
			listPank1 = new JList<String>();
			listPank1.setSelectionBackground(new Color(33, 42, 52));
			listPank1.setSelectionForeground(Color.white);
			listPank1.setForeground(Color.yellow);
			listPank1.setFont(new Font("楷体", 1, 16));
			listPank1.setBackground(new Color(0, 0, 0, 0)); // 设置列表框为透明背景
			listPank1.setFixedCellHeight(25);
			pankModel1.addElement("点击要查看的地图名称");
			listPank1.setModel(pankModel1);
			//点击飞
			// 申请列表对象
			listPank.addMouseListener(new MouseListener() {

				@Override
				public void mouseReleased(MouseEvent e) {
					// TODO Auto-generated method stub

				}

				@Override
				public void mousePressed(MouseEvent e) {
					// TODO Auto-generated method stub

				}

				@Override
				public void mouseExited(MouseEvent e) {
					// TODO Auto-generated method stub

				}

				@Override
				public void mouseEntered(MouseEvent e) {
					// TODO Auto-generated method stub

				}

				@Override
				public void mouseClicked(MouseEvent e) {
					pankModel1 = new DefaultListModel<String>();
					if (listPank.getSelectedIndex() != -1) {
						int indexs = listPank.getSelectedIndex();
						Map<String, Object> maps = dataNpcMapListSX.get(indexs);
						List<Map<String, Object>> list = (List<Map<String, Object>>) maps.get("npcList");
						for(int i=0;i<list.size();i++) {
							pankModel1.addElement(list.get(i).get("npcName").toString()+","+maps.get("mapid").toString()+","+maps.get("mapName").toString()+"("+Integer.parseInt(list.get(i).get("npcx").toString())/20+","+Integer.parseInt(list.get(i).get("npcy").toString())/20+")");
							listPank1.setModel(pankModel1);

							listPank1.addMouseListener(new MouseListener() {

								@Override
								public void mouseReleased(MouseEvent e) {
									// TODO Auto-generated method stub

								}

								@Override
								public void mousePressed(MouseEvent e) {
									// TODO Auto-generated method stub

								}

								@Override
								public void mouseExited(MouseEvent e) {
									// TODO Auto-generated method stub

								}

								@Override
								public void mouseEntered(MouseEvent e) {
									// TODO Auto-generated method stub

								}

								@Override
								public void mouseClicked(MouseEvent e) {
									pankModel1 = new DefaultListModel<String>();
									if (listPank1.getSelectedIndex() != -1) {
										List<String> kka = listPank1.getSelectedValuesList();
										feizb(kka);
									}
								}

							});
						}
					}
				}

			});
		}
	}

	//传送 坐标
	public static void iWantToFly() {
		if (ImageMixDeal.userimg.getRoleShow().getBooth_id() != null) {
			ZhuFrame.getZhuJpanel().addPrompt2("摆摊状态不可以移动！");
			return;
		}
		String flag=Util.mapmodel.getGamemap().getMapflag();
		if (flag == null||!"1".equals(flag)||ImageMixDeal.userimg.getTeams()==null) {
			ZhuFrame.getZhuJpanel().addPrompt2("当前地图不可以飞行！");
			return;
		}
		if(npcfeiji == null || npcfeiji.length() == 0) {
			ZhuFrame.getZhuJpanel().addPrompt2("请先搜索NPC!!!");
		}else {
			String kkf = "传送="+npcfeiji+", 可用次数=10";
			String kkf0 = "传送="+npcfeiji;
			String kkf1 = npcfeiji;
			String[] vs =kkf.split(",");
			String[] cishu = vs[vs.length - 1].split("=");
			int sum = Integer.parseInt(cishu[1]);
			--sum;
			String[] path = null;
			StringBuffer buffer = new StringBuffer();
			if (buffer.length() != 0) {
				buffer.append("|");
			}

			buffer.append(kkf0);
			if (path == null) {
				String[] pathv = kkf1.split(",");
				String wz = pathv[1] + "(" + pathv[2] + "," + pathv[3] + ")";
				path = pathv;
			}

			if (buffer.length() != 0) {
				buffer.append("|");
			}

			buffer.append(cishu[0]);
			buffer.append("=");
			buffer.append(sum);
			if (path != null) {
//				NPCJfram.getNpcJfram().getNpcjpanel().getGood().setValue(buffer.toString());
				if (sum <= 0) {
					NPCJfram.getNpcJfram().getNpcjpanel().getGood().setUsetime(0);
				}

				GoodsMouslisten.gooduse(NPCJfram.getNpcJfram().getNpcjpanel().getGood(), 2);
				if (sum <= 0) {
					GoodsListFromServerUntil.Deletebiaoid(NPCJfram.getNpcJfram().getNpcjpanel().getGood().getRgid());
				}

				Door door = new Door();
				door.setDoormap(path[0]);
				door.setDoorpoint(path[2] + "|" + path[3]);

				try {
					TP.tp(door, 1);
				} catch (Exception var9) {
					var9.printStackTrace();
				}
			}
		}
	}


	private static void ChaojifeiListJpanel() {
		// TODO Auto-generated method stub

	}

	/** 查询确定 */
	public static List<Map<String, Object>> findEnsure() {
		if(findName.getText() == null || findName.getText().length() == 0) {
			ZhuFrame.getZhuJpanel().addPrompt2("请输入要查找的NPC名称！");
			return null;
		}

		//总数据
		List<Map<String, Object>> dataNpcMapList = new ArrayList<Map<String, Object>>();

		//npc数据
		List<Npctable> npcList = new ArrayList<Npctable>();
		AllNpcBean allNpcBean = UserMessUntil.getAllNpcBean();
		if(allNpcBean!=null) {
			Map<String, NpcInfoBean> npc = allNpcBean.getAllNpcInfo();
			for (Entry<String, NpcInfoBean> entry : npc.entrySet()) {
				if(entry.getValue().getNpctable().getNpcname()!=null && !"".equals(entry.getValue().getNpctable().getNpcname())) {
					npcList.add(entry.getValue().getNpctable());
				}
			}
		}
		//map数据
		AllMapBean allMapBean = UserMessUntil.getAllmapbean();
		Map<String, Gamemap> mapa = allMapBean.getAllMap();
		List<Gamemap> mapListALL = new ArrayList<Gamemap>();
		List<Gamemap> mapList = new ArrayList<Gamemap>();
		for (Entry<String, Gamemap> entry : mapa.entrySet()) {
			if(entry.getValue().getMapnpc()!=null && !"".equals(entry.getValue().getMapnpc())) {
				mapListALL.add(entry.getValue());
			}
		}
		if(mapListALL!=null &&mapListALL.size()>0) {
			for(Gamemap gamemap:mapListALL) {
				if("1".equals(gamemap.getMapflag())) {
					mapList.add(gamemap);
				}
			}
		}




		if(mapList!=null && mapList.size()>0) {
			for(Gamemap gamemap:mapList) {
				List<Map<String, Object>> mapNpcList = new ArrayList<Map<String, Object>>();
				Map<String, Object> maps = new HashMap<>();
				int x = Integer.parseInt(gamemap.getWidth())/2;
				int y = Integer.parseInt(gamemap.getHeight())/2;
				String mapid = gamemap.getMapid();
				String mapName = gamemap.getMapname();
				String mapxy = x+","+y;
				String[] mapnpc = gamemap.getMapnpc().split("\\|");
				List<String> mapnpcList = new ArrayList<String>();
				if(mapnpc!=null && mapnpc.length>0) {
					for(String npcs:mapnpc) {
						int result1 = npcs.indexOf("-");
						if(result1 != -1){
							String[] mapnpcs = npcs.split("\\-");
							if(mapnpcs.length>1) {
								int i = Integer.parseInt(mapnpcs[1])-Integer.parseInt(mapnpcs[0])+1;
								for(int j =0; j<i; j++) {
									int s = Integer.parseInt(mapnpcs[0])+j;
									mapnpcList.add(s+"");
								}
							}
						}else {
							mapnpcList.add(npcs);
						}
					}
					//

					if(mapnpcList!=null && mapnpcList.size()>0) {
						for(String npc : mapnpcList) {
							for(Npctable npctable:npcList) {
								if(npc.equals(npctable.getNpcid())) {
									Map<String, Object> mapNpc = new HashMap<>();
									mapNpc.put("npcName", npctable.getNpcname());
									mapNpc.put("npcx", npctable.getTx());
									mapNpc.put("npcy", npctable.getTy());
									mapNpcList.add(mapNpc);
								}
							}
						}
					}
				}
				maps.put("mapid",  mapid);
				maps.put("mapName",  mapName);
				maps.put("mapxy",  mapxy);
				if(mapNpcList!=null && mapNpcList.size()>0) {
					maps.put("npcList",  mapNpcList);
					dataNpcMapList.add(maps);
				}
			}
		}
		List<Map<String, Object>> dataNpcMapListC = new ArrayList<Map<String, Object>>();
		if(dataNpcMapList!=null && dataNpcMapList.size()>0) {
			for(Map<String, Object> map:dataNpcMapList) {
				for(Gamemap gamemap:mapList) {
					if(map.get("mapid").toString().equals(gamemap.getMapid())) {
						dataNpcMapListC.add(map);
					}
				}
			}
		}

		dataNpcMapList = dataNpcMapListC;


//		//system.out.println(dataNpcMapList);
		//npc名字检索
		String text = findName.getText();
		//地图检索
//		String text1 = findName1.getText();
		//检索后的总数据
		List<Map<String, Object>> dataNpcMapListJS = new ArrayList<Map<String, Object>>();

		if(dataNpcMapList!=null && dataNpcMapList.size()>0) {
			for(Map<String, Object> map : dataNpcMapList) {
				Map<String, Object> maps = new HashMap<>();
				List<Map<String, Object>> mapNpcList2 = new ArrayList<Map<String, Object>>();
				List<Map<String, Object>> mapNpcList = (List<Map<String, Object>>) map.get("npcList");
				if(mapNpcList!=null && mapNpcList.size()>0) {
					for(Map<String, Object> map2:mapNpcList) {
						int result1 = map2.get("npcName").toString().indexOf(text);
						if(result1 != -1){
							mapNpcList2.add(map2);
							maps = map;
							maps.put("npcList",  mapNpcList2);
							dataNpcMapListJS.add(maps);
						}
					}
				}
			}
		}
		//如果有检索数据去重
		if(text!=null && text.length()>0) {
			dataNpcMapList = removeRepeatMapByKey(dataNpcMapListJS,"mapName");
		}
		//返回最终结果
		if(dataNpcMapList!=null && dataNpcMapList.size()>0) {
			List<Map<String, Object>> npc = (List<Map<String, Object>>) dataNpcMapList.get(0).get("npcList");
			if(npc!=null && npc.size()>0) {
				labtext5.setText(dataNpcMapList.get(0).get("mapName").toString()+"("+Long.parseLong(npc.get(0).get("npcx").toString())/20+","+Long.parseLong(npc.get(0).get("npcy").toString())/20+")");
				npcfeiji = dataNpcMapList.get(0).get("mapid").toString()+","+dataNpcMapList.get(0).get("mapName").toString()+","+npc.get(0).get("npcx").toString()+","+npc.get(0).get("npcy").toString();
			}
		}else {
			labtext5.setText("未查到NPC！");
			npcfeiji = null;
		}

//		getlisysta(dataNpcMapList);
//		ChaojifeiListJpanel();
		return dataNpcMapList;
	}

	private static void ChaojifeiListJpanel(List<Map<String, Object>> dataNpcMapList) {
		// TODO Auto-generated method stub

	}

	public static void feizb(List<String> selectNpc) {

		//npcfeiji 1211,地府,748,935
		String feiji = selectNpc.get(0);

		String str11=feiji.substring(0, feiji.indexOf(","));
		String str22=feiji.substring(str11.length()+1, feiji.length());

		String str111=str22.substring(0, str22.indexOf(","));
		String str222=str22.substring(str111.length()+1, str22.length());

		labtext5.setText(str222);

		feiji = feiji.replace("(", ",");
		feiji = feiji.replace(")", "");
		String str1=feiji.substring(0, feiji.indexOf(","));
		String str2=feiji.substring(str1.length()+1, feiji.length());
		String[] str3 = str2.split(",");
		str3[2] =(Long.parseLong(str3[2])*20)+"";
		str3[3] =(Long.parseLong(str3[3])*20)+"";
		npcfeiji = str3[0]+","+str3[1]+","+str3[2]+","+str3[3];
	}


	private ImageIcon icon = CutButtonImage.getImage("inkImg/newbackground/B331.png", 540, 480);
	private ImageIcon icon1 = CutButtonImage.getImage("skin/8100226/button/hongmu/NPC查询红木.png", 540, 480);

	public static int getCurrentMonthDay() {
		Calendar a = Calendar.getInstance();

		a.set(Calendar.DATE, 1);

		a.roll(Calendar.DATE, -1);

		int maxDate = a.get(Calendar.DATE);

		return maxDate;

	}

	@Override
	protected void paintComponent(Graphics g) {
		if (MyIsif.getStyle().equals("水墨UI")){
			super.paintComponent(g);
			g.drawImage(icon.getImage(), 0, 0,540, 480, this);
		}else {
			super.paintComponent(g);
			g.drawImage(icon1.getImage(), 0, 0,540, 480, this);
		}
	}

	public DefaultTableModel getTableModel() {
		return tableModel;
	}

	public void setTableModel(DefaultTableModel tableModel) {
		ChaojifeiListJpanel.tableModel = tableModel;
	}

	public static JTextField getFindName() {
		return findName;
	}

	public static void setFindName(JTextField findName) {
		ChaojifeiListJpanel.findName = findName;
	}

	public static JTextField getFindName1() {
		return findName1;
	}

	public static void setFindName1(JTextField findName1) {
		ChaojifeiListJpanel.findName1 = findName1;
	}

	public Goodstable getGood() {
		return good;
	}

	public void setGood(Goodstable good) {
		this.good = good;
	}

	public String[] getFvalue() {
		return Fvalue;
	}

	public void setFvalue(String[] fvalue) {
		Fvalue = fvalue;
	}

	public JTextArea getTestMes() {
		return testMes;
	}

	public void setTestMes(JTextArea testMes) {
		ChaojifeiListJpanel.testMes = testMes;
	}

	/**
	 * 根据map中的某个key 去除List中重复的map
	 * @author  shijing
	 * @param list
	 * @param mapKey
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static List<Map<String, Object>> removeRepeatMapByKey(List<Map<String, Object>>
																		 list, String mapKey){
//        if (CollectionUtils.isNotEmpty(list)) return null;

		//把list中的数据转换成msp,去掉同一id值多余数据，保留查找到第一个id值对应的数据
		List<Map<String, Object>> listMap = new ArrayList<>();
		Map<String, Map> msp = new HashMap<>();
		for(int i = list.size()-1 ; i>=0; i--){
			Map map = list.get(i);
			String id = (String)map.get(mapKey);
			map.remove(mapKey);
			msp.put(id, map);
		}
		//把msp再转换成list,就会得到根据某一字段去掉重复的数据的List<Map>
		Set<String> mspKey = msp.keySet();
		for(String key: mspKey){
			Map newMap = msp.get(key);
			newMap.put(mapKey, key);
			listMap.add(newMap);
		}
		return listMap;
	}
}
